package main

import (
	"github.com/gin-gonic/gin"
	"cookbook-go/controller"
	"flag"
)

func main() {
	url := flag.String("url", "http://119.29.116.62:9200", "Use -url <the es client url path>")
	mode := flag.Bool("prod", false, "Use -prod <run app in production mode>")
	flag.Parse()
	if *mode {
		gin.SetMode(gin.ReleaseMode)
	}
	router := gin.Default()
	router.Static("/static", "./public")
	router.LoadHTMLGlob("views/*")
	router.GET("/", func(c *gin.Context) {
		c.HTML(200, "index.html", nil)
	})
	router.GET("/ping",
		func(c *gin.Context) {
			c.JSON(200, gin.H{
				"message": "pong",
			})
		})

	elasticController := controller.InitElasticController(*url)
	api := router.Group("/api/v1")
	{
		api.GET("/", elasticController.GetOneById)
		api.GET("/lastest", elasticController.GetLatestByPage)
		api.GET("/hotest", elasticController.GetHotestByPage)
		api.GET("/coursels", elasticController.GetCoursels)
		api.GET("/category", elasticController.GetByCategory)
		api.GET("/search", elasticController.SearchByKeyword)
		api.GET("/searchDSL", elasticController.SpecialSearch)
		api.POST("/proxyQuery", elasticController.ProxyQuery)
		api.GET("/wordAnalyze", elasticController.WordAnalyze)
	}

	router.Run(":3000")
}
